#include <iostream>
#include <cstdio>
#include <vector> 
#include <algorithm>

using namespace std; 

struct student_t {
	int id; 
	int chinese, math, english; 
	int total; 
}; 

bool cmp_w(student_t &a, student_t &b)
{
	return (a.total==b.total) ? 
			(a.chinese==b.chinese ? (a.id<b.id) : (a.chinese>b.chinese)) : 
			(a.total>b.total); 
}

int main()
{
	int i, n; 
	vector <student_t> sd; 
	student_t s; 
	int total = 0; 
	
	//freopen("p1093.in", "r", stdin); 
	
	cin>>n; 
	for (i=0; i<n; i++) {
		s.id = i+1; 
		cin>>s.chinese>>s.math>>s.english; 
		s.total = s.chinese+s.math+s.english; 
		sd.push_back(s); 
	}
	
	sort(sd.begin(), sd.end(), cmp_w); 

	for (i=0; i<5; i++) {
		cout<<sd[i].id<<" "<<sd[i].total<<"\n"; 
	}
	
	return 0; 
}


